package com.itheima.store.service.impl;

import java.sql.SQLException;
import java.util.List;


import com.itheima.store.dao.DeptmanagerDao;

import com.itheima.store.domain.Dept;

import com.itheima.store.service.DeptManagerService;
import com.itheima.store.utils.BeanFactory;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
/**
 * 分类的Service的实现类
 * @author admin
 *
 */
public class DeptManagerServiceImpl implements DeptManagerService {

	//@Override
	public List<Dept> findAllDept()throws SQLException {
		List<Dept> list = null;
		DeptmanagerDao deptmanagerDao =(DeptmanagerDao)BeanFactory.getBean("deptmanagerDao");
		list = deptmanagerDao.findAllDept();
		return list;
	}

	@Override
	public void savesaveDept(Dept dept) throws SQLException {
		// TODO Auto-generated method stub
		DeptmanagerDao deptmanagerDao =(DeptmanagerDao)BeanFactory.getBean("deptmanagerDao");
		deptmanagerDao.saveDept(dept);
		//清空缓存
		//CacheManager cacheManager = CacheManager.create(DeptManagerServiceImpl.class.getClassLoader().getResourceAsStream("ehcache.xml"));
		// 从配置文件中获取名称为categoryCache缓存区
		//Cache cache = cacheManager.getCache("deptmanagerCache");
		//cache.remove("list");
		
	}

	@Override
	public Dept queryDept(String dept_id) throws SQLException {
		DeptmanagerDao deptmanagerDao =(DeptmanagerDao)BeanFactory.getBean("deptmanagerDao");
		
		return deptmanagerDao.queryDept(dept_id);
	}

	@Override
	public void updateDept(Dept dept) throws SQLException {
		DeptmanagerDao deptmanagerDao =(DeptmanagerDao)BeanFactory.getBean("deptmanagerDao");
		deptmanagerDao.updateDept(dept);
	}

	@Override
	public void deleteDept(String dept_id) throws SQLException {
		// TODO Auto-generated method stub
		DeptmanagerDao deptmanagerDao =(DeptmanagerDao)BeanFactory.getBean("deptmanagerDao");
		deptmanagerDao.deleteDept(dept_id);
		
	}

}
